package com.autocloud.repository;

import com.autocloud.model.security.Account;
import com.autocloud.model.security.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @author zhongwb
 * @version 1.0
 * @description
 * @date 2019/12/14 4:38 下午
 */
@Repository
public interface AccountRepository extends JpaRepository<Account, String> {

    @Query("" +
            " SELECT ux FROM Account ux " +
            " join Person u0 on ux.person = u0.id  " +
            " WHERE ux.account = ?1 ")
    Optional<Account> findByAccount(String username);

    @Query("" +
            " SELECT u0 FROM Account ux " +
            " join Person u0 on ux.person = u0.id " +
            " WHERE ux.id = ?1 ")
    Optional<Person> findByAccountId(String accountId);

    List<Account> findAllByIdIn(List<String> ids);


}
